﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using LitJson;

public class ClearSceneMaster : MonoBehaviour {

	GameMaster gameMaster;
	Text text_msg;

	// Use this for initialization
	void Awake () {
		GameObject obj = GameObject.Find ("GameMaster");
		if(obj != null) gameMaster = obj.GetComponent<GameMaster>();
		text_msg = GameObject.Find("MSG").GetComponent<Text>();

		if (gameMaster == null) {
			text_msg.text = "没有发现GameMaster!";
			return;
		}

		gameMaster.gameObject.SetActive (false);

		text_msg.text = "死亡次数: " + gameMaster.Death;

		//连接服务器
		StartCoroutine(a());
	}


	public IEnumerator a(){
		string name = "Plyaer" + Random.Range (1, 65535);
		WWW www = new WWW ("http://127.0.0.1/HelloPHP.php?name=" + name + "&deaths=" + gameMaster.Death);
		yield return www;
		if (string.IsNullOrEmpty (www.error)) {
			JsonData jd = new JsonData(www.text);
			for(int i = 0; i< jd.Count; i++){
				//jd[]
			}
		} else {
			Debug.Log (www.error);
		}
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
